package com.shelpe.services.sinbad.dto;

import org.springframework.beans.BeanUtils;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.shelpe.services.sinbad.model.Keyword;
import com.shelpe.services.sinbad.model.RptKeyword;

import lombok.Data;

@Data
public class KeywordDto {
	private String title;
	private String url;
	@JsonProperty("product_id")
	private long productID;
	@JsonProperty("keyword_id")
	private long keywordID;
	@JsonProperty("max_mobile_price")
	private int maxMobilePrice;
	@JsonProperty("max_price")
	private int maxPrice;
	@JsonProperty("mobile_is_default_price")
	private int mobileIsDefaultPrice;
	private int matchscope;
	@JsonProperty("is_default_price")
	private int isDefaultPrice;
	private String word;
	private float cpc;
	private float ctr;
	private float roi;
	private int impressions;
	private float cpm;
	private int click;
	private int cost;
	private float avgpos;
	@JsonProperty("direct_pay")
	private int directPay;
	@JsonProperty("indirect_pay")
	private int indirectPay;
	@JsonProperty("direct_pay_count")
	private int directPayCount;
	@JsonProperty("indirect_pay_count")
	private int indirectPayCount;
	@JsonProperty("fav_shop_count")
	private int favShopCount;
	@JsonProperty("fav_item_count")
	private int favItemCount;
	@JsonProperty("direct_cart_total")
	private int directCartTotal;
	@JsonProperty("indirect_cart_total")
	private int indirectCartTotal;
	@JsonProperty("cart_total")
	private int cartTotal;

	/**
	 * 以下几个字段都是计算得出来
	 */
	private float cvr;
	@JsonProperty("fav_count_rate")
	private float favCountRate;
	@JsonProperty("cart_count_rate")
	private float cartCountRate;
	@JsonProperty("pay_count")
	private int payCount;
	private float sale;
	@JsonProperty("fav_count")
	private float favCount;

	/**
	 * 以下几个字段只有在source为23的有效
	 */
	@JsonProperty("qscore")
	private int pcQscore;
	@JsonProperty("wireless_qscore")
	private int mobileQscore;

	public void from(Keyword keyword, int discount) {
		this.keywordID = keyword.getKeywordId();
		this.maxPrice = keyword.getMaxPrice();
		this.mobileIsDefaultPrice = keyword.getMobileIsDefaultPrice();
		this.word = keyword.getWord();
		if (keyword.getWirelessQscore() != null) {
			this.mobileQscore = keyword.getWirelessQscore();
		}
		if (keyword.getQscore() != null) {
			this.pcQscore = keyword.getQscore();
		}
		if (keyword.getMaxMobilePrice() > 0) {
			this.maxMobilePrice = keyword.getMaxMobilePrice();
		} else {
			this.maxMobilePrice = keyword.getMaxPrice() * (discount / 100);
		}
	}

	public void from(RptKeyword rpt) {
		BeanUtils.copyProperties(rpt, this);
		this.favCount = rpt.getFavItemCount() + rpt.getFavShopCount();
		this.cpc = rpt.getCpc();
		this.ctr = rpt.getCtr();
		this.roi = rpt.getRoi();
	}
}
